package com.zuipin.controller;

import java.math.BigDecimal;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.zuipin.entity.SysUserResource;
import com.zuipin.framework.annotation.Inject;
import com.zuipin.framework.annotation.Valid;
import com.zuipin.framework.annotation.Valids;
import com.zuipin.framework.emuns.ErrorCode;
import com.zuipin.framework.result.PageResult;
import com.zuipin.framework.result.Result;
import com.zuipin.service.ISysUserResourceService;
import com.zuipin.util.Pagination;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import springfox.documentation.annotations.ApiIgnore;

/**
 * 用户-数据-权限 关系Controller
 * 
 * @ClassName: SysUserResourceController
 * @Description: TODO
 * @author robot
 * @date 2017年09月147日 09:21:09
 */
@Api(value = "用户-数据-权限 关系", description = "用户-数据-权限 关系")
@RestController
@RequestMapping(value = "/sysUserResource")
public class  SysUserResourceController {
	@Resource
	public ISysUserResourceService sysUserResourceService;

	
	@RequestMapping(value = "/get", method = RequestMethod.GET)
	@ApiOperation(value = "根据主键查询用户-数据-权限 关系", notes = "查询用户-数据-权限 关系")
	public Result<SysUserResource> getSysUserResourceById(@ApiParam(required = true, name = "id", value = "主键 序列自增") @RequestParam Long id){
		SysUserResource sysUserResource = sysUserResourceService.findById(id);
		Result<SysUserResource> result = new Result<SysUserResource>();
		if (sysUserResource != null) {
			result.setData(sysUserResource);
			result.setErrorCode(ErrorCode.SUCCESS);
		} else {
			result.setErrorCode(ErrorCode.ELSE);
		}
		return result;
	}
	
	@RequestMapping(value = "/insert", method = RequestMethod.POST)
	@ApiOperation(value = "新增用户-数据-权限 关系", notes = "新增用户-数据-权限 关系")
	@Valids({
		
		@Valid(name = "sysUserResource.userId",  maxLength = 19),
		@Valid(name = "sysUserResource.columnName",  maxLength = 50),
		@Valid(name = "sysUserResource.tableName",  maxLength = 50),
		@Valid(name = "sysUserResource.powerType",  maxLength = 5),
		@Valid(name = "sysUserResource.valueIds",  maxLength = 255),
	})
	@ApiImplicitParams({
		
		@ApiImplicitParam(name = "sysUserResource.userId", value = "系统用户", required = true, dataType = "userId", paramType = "query"),
		@ApiImplicitParam(name = "sysUserResource.columnName", value = "权限所属列名",  dataType = "columnName", paramType = "query"),
		@ApiImplicitParam(name = "sysUserResource.tableName", value = "数据权限对应的表名", required = true, dataType = "tableName", paramType = "query"),
		@ApiImplicitParam(name = "sysUserResource.powerType", value = "权限类型 all：所有权限 edit：操作权限 query：查询权限", required = true, dataType = "powerType", paramType = "query"),
		@ApiImplicitParam(name = "sysUserResource.valueIds", value = "该表对应的数据", required = true, dataType = "valueIds", paramType = "query"),
	})
	public Result<SysUserResource> insertSysUserResource(@Inject @ApiIgnore SysUserResource sysUserResource) {
		Result<SysUserResource> result = new Result<SysUserResource>();
		sysUserResourceService.insert(sysUserResource);
		result.setData(sysUserResource);
		result.setErrorCode(ErrorCode.SUCCESS);
		return result;
	}
	
	@RequestMapping(value = "/update", method = RequestMethod.POST)
	@ApiOperation(value = "根据主键修改用户-数据-权限 关系", notes = "修改用户-数据-权限 关系")
	@Valids({ 
		@Valid(name = "sysUserResource.id",  maxLength = 19),
		@Valid(name = "sysUserResource.userId",  maxLength = 19),
		@Valid(name = "sysUserResource.columnName",  maxLength = 50),
		@Valid(name = "sysUserResource.tableName",  maxLength = 50),
		@Valid(name = "sysUserResource.powerType",  maxLength = 5),
		@Valid(name = "sysUserResource.valueIds",  maxLength = 255),
	})
	@ApiImplicitParams({
		@ApiImplicitParam(name = "sysUserResource.id", value = "主键 序列自增", required = true, dataType = "id", paramType = "query"),
		@ApiImplicitParam(name = "sysUserResource.userId", value = "系统用户", required = true, dataType = "userId", paramType = "query"),
		@ApiImplicitParam(name = "sysUserResource.columnName", value = "权限所属列名", dataType = "columnName", paramType = "query"),
		@ApiImplicitParam(name = "sysUserResource.tableName", value = "数据权限对应的表名", required = true, dataType = "tableName", paramType = "query"),
		@ApiImplicitParam(name = "sysUserResource.powerType", value = "权限类型 all：所有权限 edit：操作权限 query：查询权限", required = true, dataType = "powerType", paramType = "query"),
		@ApiImplicitParam(name = "sysUserResource.valueIds", value = "该表对应的数据", required = true, dataType = "valueIds", paramType = "query"),
	})
	public Result<SysUserResource> updateSysUserResource(@Inject @ApiIgnore SysUserResource sysUserResource) {
		Result<SysUserResource> result = new Result<SysUserResource>();
		sysUserResourceService.update(sysUserResource);
		result.setErrorCode(ErrorCode.SUCCESS);
		return result;
	}
	
	@RequestMapping(value = "/del", method = RequestMethod.DELETE)
	@ApiOperation(value = "根据主键删除用户-数据-权限 关系", notes = "删除用户-数据-权限 关系")
	public Result<SysUserResource> delSysUserResource( Long id) {
		Result<SysUserResource> result = new Result<SysUserResource>();
		sysUserResourceService.delete(id);
		result.setErrorCode(ErrorCode.SUCCESS);
		return result;
	}
	
	@RequestMapping(value = "/seach", method = RequestMethod.POST)
	@ApiOperation(value = "搜索用户-数据-权限 关系SKU用户-数据-权限 关系并分页", notes = "搜索用户-数据-权限 关系并分页")
	@Valids({
		
		@Valid(name = "sysUserResource.userId",  maxLength = 19),
		@Valid(name = "sysUserResource.columnName",  maxLength = 50),
		@Valid(name = "sysUserResource.tableName",  maxLength = 50),
		@Valid(name = "sysUserResource.powerType",  maxLength = 5),
		@Valid(name = "sysUserResource.valueIds",  maxLength = 255),
		@Valid(name = "page.pageNumber",  maxValue = 999),
		@Valid(name = "page.pageSize",  maxValue = 999),
	})
	@ApiImplicitParams({
		
		@ApiImplicitParam(name = "sysUserResource.userId", value = "系统用户", required = true, dataType = "userId", paramType = "query"),
		@ApiImplicitParam(name = "sysUserResource.columnName", value = "权限所属列名", dataType = "columnName", paramType = "query"),
		@ApiImplicitParam(name = "sysUserResource.tableName", value = "数据权限对应的表名", required = true, dataType = "tableName", paramType = "query"),
		@ApiImplicitParam(name = "sysUserResource.powerType", value = "权限类型 all：所有权限 edit：操作权限 query：查询权限", required = true, dataType = "powerType", paramType = "query"),
		@ApiImplicitParam(name = "sysUserResource.valueIds", value = "该表对应的数据", required = true, dataType = "valueIds", paramType = "query"),
		@ApiImplicitParam(name = "page.pageNumber", value = "页码", required = true, dataType = "integer", paramType = "query"),
		@ApiImplicitParam(name = "page.pageSize", value = "单页记录数", required = true, dataType = "integer", paramType = "query"),
	})
	public Result<List<SysUserResource>> seachSysUserResource(@Inject @ApiIgnore SysUserResource sysUserResource,
			@Inject @ApiIgnore Pagination page) {
		PageResult<List<SysUserResource>> result = new PageResult<List<SysUserResource>>();
		result.setData(sysUserResourceService.seachSysUserResource(sysUserResource, page));
		result.setTotal_record(page.getTotalRecord());
		result.setErrorCode(ErrorCode.SUCCESS);
		return result;
	}
	
}
